<template>
  <div class="container">
    <div class="export-header">
      <el-button type="primary" size='medium' @click="$router.push('/signEdit')">录入签约信息</el-button>
    </div>
    <div class="input_modal">
      <div class="input-item">
        <span>昵称：</span>
        <el-input v-model="userName" placeholder="请输入内容" class="proName" @keyup.enter.native="search"></el-input>
      </div>
      <div class="input-item">
        <span>姓名：</span>
        <el-input v-model="realname" placeholder="请输入内容" class="proName" @keyup.enter.native="search"></el-input>
      </div>
      <div class="input-item">
        <span>手机号：</span>
        <el-input v-model="mobile" placeholder="请输入内容" class="proName" @keyup.enter.native="search"></el-input>
      </div>
      <div class="input-item">
        <span>办公室名称：</span>
        <el-input v-model="roomName" placeholder="请输入内容" class="proName" @keyup.enter.native="search"></el-input>
      </div>
      <div class="input-item">
        <el-button icon="el-icon-search" type="primary" size="medium" @click="getList">查询</el-button>
      </div>
    </div>
    <div class="table_con">
      <el-table v-loading="loading" :data="tableData" :border='true'>
        <el-table-column :formatter="formatter" prop="userName" label="昵称"></el-table-column>
        <el-table-column :formatter="formatter" prop="realname" label="姓名"></el-table-column>
        <el-table-column :formatter="formatter" prop="mobile" label="手机号"></el-table-column>
        <el-table-column :formatter="formatter" prop="buildingName" label="所属写字楼"></el-table-column>
        <el-table-column :formatter="formatter" prop="roomName" label="办公室名称"></el-table-column>
        <el-table-column :formatter="formatter" prop="signingDate" label="签约日期"></el-table-column>
        <el-table-column :formatter="formatter" prop="signingLimit" label="签约期限"></el-table-column>
        <el-table-column :formatter="formatter" prop="dueDate" label="到期日期"></el-table-column>
        <el-table-column prop="" label="操作" width='120'>
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="$router.push('/signEdit?id='+scope.row.id)">编辑</el-button>
            <el-button type="primary" size="mini" @click="handleDel(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="pagination">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="pageIndex" :page-size="pageSize" :page-sizes='[10,20,30,40]' layout="total, sizes, prev, pager, next, jumper" :total="pageCount">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  let CONSTANT = require("../../constant/constant.js");
  let common = require("../../common.js");
  export default {
    data() {
      return {
        tableData: [],
        pageCount: null,
        pageIndex: 1,
        pageSize: 10,
        loading: true,
        mobile: null,
        nickname:null,
        name: "",
        realname: "",
        roomName: "",
        userName: "",
      };
    },
    mounted() {
      this.getList();
    },
    methods: {
      formatter(row, column, cellValue) {
        return cellValue ? cellValue : "- -";
      },
      getList: function() {
        let url = CONSTANT.URL.SIGN.list;
        let data = {
          pageIndex: this.pageIndex,
          pageSize: this.pageSize,
          realname: this.realname,
          roomName: this.roomName,
          userName: this.userName,
          mobile: this.mobile
        };
        this.loading = true;
        common.requestAjax(url, JSON.stringify(data), null, res => {
          this.loading = false;
          let data = res.data;
          this.tableData = data.bussData;
          this.pageCount = data.count;
        });
      },
      handleDel(id) {
        this.$confirm("确定删除?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            let url = CONSTANT.URL.SIGN.del;
            common.del(url, id, res => {
              if (res.status == 200) {
                this.$message({
                  type: "success",
                  message: "删除成功!"
                });
                this.getList();
              } else {
                this.$message({
                  type: "warning",
                  message: res.data.errMsg
                });
              }
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除"
            });
          });
      },
      search: function(e) {
        if (e.keyCode == 13) {
          this.pageIndex = 1;
          this.getList();
        }
      },
      handleSizeChange(val) {
        this.pageSize = val;
        this.getList();
      },
      handleCurrentChange(val) {
        this.pageIndex = val;
        this.getList();
      }
    }
  };
</script>
